package com.bzkj.web.controller.msfx;


import com.bzkj.common.annotation.LogD;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.msfx.domain.MsfxCustomer;
import com.bzkj.msfx.service.MsfxCustomerService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: bzkj-wms
 * @package: com.bzkj.wms.web.controller.msfx
 * @className: MsfxCustomerController
 * @description: 码上放心客户信息控制层
 * @author: C1309
 * @createDate: 2024年10月22日
 * @version: v1.0
 */
@RestController
@RequestMapping("/btrh/msfx/customer")
public class MsfxCustomerController extends BaseController {

    /**
     * 码上放心客户信息服务层
     */
    @Resource
    MsfxCustomerService msfxCustomerService;

    @Value("${bzkj.profile}")
    private String uploadPath;

    @Value("${pk_org.code}")
    private String factory;

    /**
     * 码上放心客户信息导入
     *
     * @param msfxCustomerFile 码上放心客户信息文件
     * @return 上传结果
     */
    @PostMapping
    @PreAuthorize("@ss.hasPermi('msfx:customer:import')")
    @LogD(title = "码上放心客户信息", businessType = BusinessType.IMPORT)
    public AjaxResult addMsfxCustomer(@RequestParam("file") MultipartFile msfxCustomerFile) {
        String filePath = uploadPath + "/upload";
        // 获取到部门id
        Long deptId = getDeptId();
        return msfxCustomerService.parsingFile(msfxCustomerFile, filePath, deptId, factory);
    }

    /**
     * 查询码上放心客户信息列表
     *
     * @param msfxCustomer 查询条件封装
     * @return 码上放心客户信息列表
     */
    @GetMapping
    @PreAuthorize("@ss.hasPermi('msfx:customer:list')")
    public TableDataInfo list(MsfxCustomer msfxCustomer) {
        startPage();
        List<MsfxCustomer> msfxCustomers = msfxCustomerService.selectMsfxCustomerList(msfxCustomer);
        return getDataTable(msfxCustomers);
    }

    /**
     * 查询码上放心客户详细信息
     *
     * @param id 数据库主键
     * @return 查询结果
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('msfx:customer:query')")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(msfxCustomerService.selectMsfxCustomerById(id));
    }

}
